<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>图结构及其算法单元测试</title>
    <!--注意：// 需要在支持 ES6 的环境下执行-->
    <script type="module">
        const graph_dfs = [
            [8, 6],
            [0, 1],
            [0, 2],
            [1, 3],
            [1, 4],
            [2, 3],
            [5, 6]
        ]

        const graph_bfs = [
            [7, 8],
            [0, 1],
            [0, 2],
            [1, 3],
            [1, 4],
            [2, 3],
            [2, 6],
            [3, 5],
            [5, 6]
        ]

        //-----------------------------测试图的 DFS 及其算法---------------------------------------------
        import {AdjSet} from '../AdjSet.js'
        import {GraphDFS} from './GraphDFS.js'
        function testGraphDFS() {
            const graphDFS = new GraphDFS(new AdjSet(graph_dfs))
            alert("图 DFS 测试结果【迭代】：\n" + graphDFS.getRes())
        }

        import {GraphDFSR} from './GraphDFSR.js'
        function testGraphDFSR() {
            const graphDFSR = new GraphDFSR(new AdjSet(graph_dfs))
            alert("图 DFS 测试结果【递归】：\n" + graphDFSR.getRes())
        }

        import {CC} from './CC.js'
        function testCC() {
            const cc = new CC(new AdjSet(graph_dfs))
            alert("图连通分量个数测试结果：\n" + cc.getCCCount())
        }

        import {CC1} from './CC1.js'
        function testCC1() {
            // 注意：这里依赖 AdjSet，所以在此之前一定要引入 AdjSet
            const cc1 = new CC1(new AdjSet(graph_dfs))
            const components = cc1.components()
            for (let i = 0; i < components.length; i++) {
                alert(`图第 ${i} 个连通分量包含的顶点的测试结果：\n` + components[i])
            }
            alert("判读顶点 0 和 6 是否相邻的测试结果：\n" + cc1.isConnected(0, 6))
        }

        import {SingleSourcePath} from './SingleSourcePath.js'
        function testSingleSourcePath() {
            const ssp = new SingleSourcePath(new AdjSet(graph_bfs), 0)
            alert("顶点 0 和 6 的路径是：\n" + ssp.path(6))
        }

        import {TwoVertexPath} from './TwoVertexPath.js'
        function testTwoVertexPath() {
            const tvp = new TwoVertexPath(new AdjSet(graph_dfs), 0, 6)
            alert("顶点 0 和 6 的路径是：\n" + tvp.getRes())
        }

        import {CycleDetection} from './CycleDetection.js'
        function testCycleDetection() {
            const cd = new CycleDetection(new AdjSet(graph_dfs))
            alert("判断是否有环：\n" + cd.getHasCycle())
        }

        import {CycleDetection1} from './CycleDetection1.js'
        function testCycleDetection1() {
            const cd = new CycleDetection1(new AdjSet(graph_dfs))
            alert("判断是否有环：\n" + cd.getHasCycle())
        }

        import {BipartitionDetection} from './BipartitionDetection.js'
        function testBipartitionDetection() {
            const bd = new BipartitionDetection(new AdjSet(graph_dfs))
            alert("判断是否是二分图：\n" + bd.getIsBipartition())
        }

        //testGraphDFS()
        //testGraphDFSR()
        //testCC()
        //testCC1()
        // testSingleSourcePath()
        // testTwoVertexPath()
        // testCycleDetection()
        //testCycleDetection1()
        //testBipartitionDetection()

    </script>
</head>
<body>

</body>
</html>